import 'package:flutter/material.dart';
import 'details.dart';
import 'package:shared_preferences/shared_preferences.dart';
import 'package:share_plus/share_plus.dart';
import 'dart:io';
import 'package:path_provider/path_provider.dart';
import 'package:firebase_analytics/firebase_analytics.dart';
import 'common/loading_spinner.dart'; // 导入公共组件
import 'package:cached_network_image/cached_network_image.dart'; //网络图片缓存到本地
import 'dart:convert';
import 'common/api_service.dart'; // 导入 ApiService 类
import 'package:flutter/services.dart';
import '../message.dart';

class FavoritePage extends StatefulWidget {
  const FavoritePage({
    super.key,
  });

  @override
  State<FavoritePage> createState() => _MyFavoritePageState();
}

class _MyFavoritePageState extends State<FavoritePage> {
  List<String> favoriteIdList = [];
  List<Map<String, dynamic>> favoritePhotoList = [];
  bool isdata = false;
  List categoryList = []; // 类别数据
  List dataList = [];
  List allDataList = []; // 图片子类别数据
  List dataMessageList = [];
  bool isLoading = false;

  int curTabIndex = 0;
  String curSubIndex = 'good-morning';
  int curSubImageIndex = 999;
  Map<String, List<Map<String, dynamic>>> dataMessageMap = {};

  static FirebaseAnalytics analytics = FirebaseAnalytics.instance;
  Future<void> _logScreenView() async {
    await analytics.logScreenView(
      screenName: 'Favorite Page ES',
      screenClass: 'FavoritePage_ES',
    );
    // setMessage('setCurrentScreen succeeded');
  }
  _saveIntList(favoriteList) async {
    final prefs = await SharedPreferences.getInstance();
    prefs.setStringList('favoriteList', favoriteList);
  }

  Future<List<String>> _getIntList() async {
    final prefs = await SharedPreferences.getInstance();
    List<String> favoriteList = prefs.getStringList('favoriteList') ?? [];
    return favoriteList;
  }

  _saveMessageList(favoriteMessageList) async {
    final prefs = await SharedPreferences.getInstance();
    // 将数据转换为 JSON 字符串
    String jsonString = jsonEncode(favoriteMessageList);
    
    // 存储 JSON 字符串
    await prefs.setString('message', jsonString);

  }

   Future<Map<String, dynamic>> _getMessageList() async {
    final prefs = await SharedPreferences.getInstance();

    // 读取 JSON 字符串
    String? jsonString = prefs.getString('message');
  
    if (jsonString != null) {
      // 将 JSON 字符串转换回 Map
      Map<String, dynamic> jsonData = jsonDecode(jsonString);
      return jsonData;
      // 打印读取的数据
    } else {
      return {};
    }
  }

  void fetchData() async {
    setState(() {
      isLoading = true;
    });
    try {
      String url = 'https://apken.oss-us-west-1.aliyuncs.com/goodmorning-es/json/category.json'; // 替换为你的 URL
      List<dynamic> jsonData = await ApiService.fetchJsonData(url);
      // print(jsonData);
      setState(() {
        categoryList = jsonData[0]['list'];
        
      });
      getFavoriteList();
    } catch (e) {
      // print(e);
    }
  }

  Future<void> getFavoriteList() async {

    List<String> favoriteList = await _getIntList();
    // print('收藏页面'+favoriteList.toString());
    List<Map<String, dynamic>> gifValues = [];
    for (var item in categoryList) {
      // 强制转换为 List<int>
      List<int> sortList = List<int>.from(item['sort']);
      List<int> gifList = List<int>.from(item['gif']);

      for (int i = 0; i < sortList.length; i++) {
        if (favoriteList.contains(sortList[i].toString())) {
          // print(sortList[i]);
          gifValues.add({"id": sortList[i], "gif":gifList[i], "category": item['id']});
        }
      }

    }
    // print('对应的 gif 值: $gifValues');
    setState(() {
      favoriteIdList = favoriteList;
      
      allDataList = gifValues;
      // dataList = gifValues;
      if(curSubImageIndex == 999){
        dataList = gifValues;
      }else{
        dataList = filterItemsByCategory(gifValues, curSubImageIndex);
      }
      isLoading = false;
    });
    print(favoriteIdList);
    print(dataList);
  }


  List filterItemsByCategory(List items, int category) {
    return items.where((item) => item['category'] == category).toList();
  }

  Future<void> getFavoriteMessageList() async {

    Map<String, dynamic> favoriteMessageList = await _getMessageList();
    // print('收藏页面'+favoriteMessageList.toString());

    // 存储结果
    Map<String, List<Map<String, dynamic>>> result = {};

    // 遍历每个分类
    favoriteMessageList.forEach((slug, ids) {
      // print(slug);
      // 查找对应的分类
      var categoryData = messageDatas.firstWhere(
        (data) => data['slug'] == slug,
        orElse: () => {'list': []} // 返回一个空的 Map，包含一个空的 list
      );
      // print('++++');
      // print(categoryData);
      List<Map<String, dynamic>> messages = [];

      // 遍历 ID 并获取文本
      for (var id in ids) {
        var message = (categoryData['list'] as List).firstWhere(
          (item) => item['id'].toString() == id,
          orElse: () => {'id': -1, 'text': '', 'like': 0} // 返回一个空的 Map
        );
        
        if (message['id'] != -1) { // 确保返回的消息有效
          messages.add({
            'id': message['id'],
            'text': message['text'],
            'like': message['like']
          });
        }
      }

      // 存储结果
      result[slug] = messages;
      // print(result[slug]);
    });

    setState(() {
      dataMessageMap = result;
      dataMessageList = result[curSubIndex] ?? [];
    });
    print(dataMessageList);
    // 打印结果
    // print(result);
  }

  @override
  void initState() {
    super.initState();
    _logScreenView();
    fetchData();
  }

  Future<void> shareAssetImage(String assetName) async {
    try {
      final bytes = await rootBundle.load(assetName);
      final tempDir = await getTemporaryDirectory();
      final tempFile = File('${tempDir.path}/shared_image.jpg');
      await tempFile.writeAsBytes(bytes.buffer.asUint8List());
      await Share.shareXFiles(
        [XFile(tempFile.path)],
        text: 'I just shared some images with you. I’d love to hear your thoughts!',
        sharePositionOrigin: const Rect.fromLTWH(0, 0, 100, 100),
        subject: 'Shared Images',
        // chooserTitle: 'Share via',
      );
    } catch (e) {
      // print('Error sharing asset image: $e');
    }
  }

  // Future<void> shareFileToWhatsApp(String assetName, String phone) async {
  //   try {
  //     final bytes = await rootBundle.load(assetName);
  //     final tempDir = await getTemporaryDirectory();
  //     final tempFile = File('${tempDir.path}/shared_image.jpg');
  //     await tempFile.writeAsBytes(bytes.buffer.asUint8List());
  //     await WhatsappShare.shareFile(
  //       phone: phone,
  //       filePath: [tempFile.path],
  //     );
  //   } catch (e) {
  //     print('Error sharing asset image: $e');
  //   }
  // }

  @override
  Widget build(BuildContext context) {
    var sizewidth = MediaQuery.of(context).size.width;
    final controller = ScrollController();
    return Container(
      decoration: BoxDecoration(
        image: curTabIndex == 1 ? const DecorationImage(
          image: AssetImage('images/message_bg.png'), 
          fit: BoxFit.cover
        ) : null,
      ), 
      child: Column(
      children: [
        const SizedBox(height: 12,),
        Row(
          mainAxisAlignment: MainAxisAlignment.center,
          children: [
            TextButton(
              onPressed: (){
                fetchData();
                setState(() {
                  curTabIndex = 0;
                  dataMessageList = [];
                });
              }, 
              style: curTabIndex == 0 ? ButtonStyle(backgroundColor: WidgetStateProperty.all(const Color.fromARGB(255, 215, 31, 39))) : null, 
              child: Text(
                'Tarjeta de saludo', 
                style: TextStyle(color: curTabIndex == 0 || curTabIndex == 1 ? Colors.white : Colors.black),
              )
            ),
            TextButton(
              onPressed: (){
                setState(() {
                  curTabIndex = 1;
                });
                getFavoriteMessageList();
              }, 
              style: curTabIndex == 1 ? ButtonStyle(backgroundColor: WidgetStateProperty.all(const Color.fromARGB(255, 215, 31, 39))) : null, 
              child: Text(
                'Mensajes', 
                style: TextStyle(color: curTabIndex == 1 ? Colors.white : Colors.black),
              )
            )
          ],
        ),
        if(curTabIndex == 1)
        ...[
          SingleChildScrollView(
            scrollDirection: Axis.horizontal,
            child: Row(
              children: [
                for(var index = 0; index < messageDatas.length; index++)
                  GestureDetector(
                    onTap: () {
                      setState(() {
                        curSubIndex = messageDatas[index]['slug'];
                        dataMessageList = dataMessageMap[curSubIndex] ?? [];
                      });
                    },
                    child: Container(
                      margin: const EdgeInsets.only(top: 12, left: 12),
                      padding: const EdgeInsets.only(left: 16, right: 16, top: 4, bottom: 4),
                      decoration: const BoxDecoration(
                        color: Color.fromRGBO(255, 255, 255, .85),
                        borderRadius: BorderRadius.all(Radius.circular(20)),
                        boxShadow: [
                          BoxShadow(
                            color: Colors.black12,
                            offset: Offset(0, 2),
                            blurRadius: 6.0,
                          ),
                        ],
                      ),
                      child: Row(
                        crossAxisAlignment: CrossAxisAlignment.center,
                        children: [
                          SizedBox(
                            width: 26,
                            height: 26,
                            child: Image.asset('images/category/${messageDatas[index]['slug']}.webp'),
                          ),
                          const SizedBox(width: 4),
                          Text(
                            messageDatas[index]['category'],
                            style:  TextStyle(
                              fontSize: 16,
                              fontFamily: 'OpenSans',
                              color: curSubIndex == messageDatas[index]['slug'] ? Colors.red : Colors.black
                            ),
                          ),
                          
                        ],
                      ),
                    ),
                  ),
                const SizedBox(width: 12,)
              ]
            ),
          ),
          const SizedBox(height: 16,),
          Expanded(child: 
          dataMessageList.isEmpty ? Column(
            mainAxisAlignment: MainAxisAlignment.center,
            children: [
              SizedBox(
                height: 128,
                child: Image.asset('images/empty.png'),
              ),
            ],
          ) : SingleChildScrollView(
            controller: controller,
            child: Column(
              children: [
                for(var index = 0; index < dataMessageList.length; index++)
                  Stack(
                    children: [
                      Container(
                        padding: const EdgeInsets.only(left: 16, right: 64, top: 48, bottom: 48),
                        width: sizewidth - 20,
                        margin: const EdgeInsets.only(bottom: 16),
                        decoration: BoxDecoration(
                          color: const Color.fromRGBO(255, 255, 255, .85),
                          borderRadius: BorderRadius.circular(4),
                          boxShadow: [
                            BoxShadow(
                              color: Colors.black.withOpacity(0.1), // 阴影颜色
                              spreadRadius: 1, // 阴影扩散半径
                              blurRadius: 3, // 模糊半径
                              offset: const Offset(0, 1), // 阴影偏移量
                            ),
                          ],
                        ),
                        child: Text(dataMessageList[index]['text']?.toString() ?? '', style: const TextStyle(fontFamily: 'OpenSans', color: Colors.black, fontSize: 16),),
                        
                      ),
                      Positioned(
                        left: 0, 
                        top: 0, 
                        child: Container(
                          width: 30,
                          height: 20,
                          decoration: const BoxDecoration(
                            color: Colors.black,
                            borderRadius: BorderRadius.only(topLeft: Radius.circular(4), bottomRight: Radius.circular(8))
                          ),
                          child: Center(
                            child: Text('${index+1}', style: const TextStyle(fontFamily: 'OpenSans', color: Colors.white, fontSize: 14),),
                          ),
                        ) ,
                      ),
                      
                      Positioned(
                        right: 8,
                        top: 12,
                        child: InkWell(
                          onTap: () {
                            Clipboard.setData(
                            ClipboardData(
                              text: dataMessageList[index]['text']?.toString() ?? '',
                            ),
                          ).then((_) {
                            ScaffoldMessenger.of(context)
                                .showSnackBar(
                              const SnackBar(
                                backgroundColor: Colors.green,
                                content: Text(
                                  'Successfully copied to clipboard!',
                                  style: TextStyle(
                                      fontFamily: 'Ubuntu',
                                      fontSize: 16),
                                ),
                              ),
                            );
                          });
                          },
                          child: Container(
                            width: 32,
                            height: 32,
                            decoration: BoxDecoration(
                              // borderRadius: BorderRadius.circular(18),
                              gradient: const LinearGradient(
                                colors: [Colors.green, Colors.blue],
                                begin: Alignment.topLeft,
                                end: Alignment.bottomRight,
                              ),
                              borderRadius: BorderRadius.circular(15),
                            ),
                            child: const Icon(Icons.copy, color: Colors.white,size: 18,),
                          ),
                        )
                      ),
                      Positioned(
                        right: 8,
                        top: 54,
                        child: InkWell(
                          onTap: () async {
                           
                            Map<String, dynamic> favoriteMessageList = await _getMessageList();
                            
                            setState(() {
                              String itemId = dataMessageList[index]['id'].toString();

                              //  print(itemId);
                              if (favoriteMessageList[curSubIndex] != null && favoriteMessageList[curSubIndex].contains(itemId)) {
                                favoriteMessageList[curSubIndex].remove(itemId);
                                dataMessageList.removeWhere((message) => message['id'].toString() == itemId);
                                // print(dataMessageList);
                                dataMessageMap.forEach((key, value) {
                                  value.removeWhere((message) => message['id'].toString() == itemId);
                                });

                              } else {
                                // 检查 slug 是否存在，如果不存在则初始化为一个空列表
                                if (favoriteMessageList[curSubIndex] == null) {
                                  favoriteMessageList[curSubIndex] = [];
                                }

                                favoriteMessageList[curSubIndex].add(itemId);
                              }
                            });
                            _saveMessageList(favoriteMessageList);
                          },
                          child: Container(
                            width: 32,
                            height: 32,
                            decoration: BoxDecoration(
                              // borderRadius: BorderRadius.circular(18),
                              gradient: const LinearGradient(
                                colors: [Colors.blue, Colors.purple],
                                begin: Alignment.topLeft,
                                end: Alignment.bottomRight,
                              ),
                              borderRadius: BorderRadius.circular(15),
                            ),
                            child: const Icon(Icons.favorite, color:Color.fromARGB(255, 255, 251, 0),size: 18,),
                          ),
                        )
                      )
                    ],
                  )
              ],
            ),
          ))
        ]
          
          ,
        if(curTabIndex == 0)...[
          SingleChildScrollView(
            scrollDirection: Axis.horizontal,
            child: Row(
              children: [
                GestureDetector(
                  onTap: () {
                    setState(() {
                      curSubImageIndex = 999;
                      dataList = allDataList;
                      // dataMessageList = dataMessageMap[curSubIndex] ?? [];
                    });
                    
                  },
                  child: Container(
                    margin: const EdgeInsets.only(top: 12, left: 12),
                    padding: const EdgeInsets.only(left: 16, right: 16, top: 4, bottom: 4),
                    decoration: BoxDecoration(
                      border: Border.all(width: 0.5, color: const Color.fromARGB(255, 211, 211, 211)),
                      color: const Color.fromRGBO(255, 255, 255, .85),
                      borderRadius: const BorderRadius.all(Radius.circular(20)),
                    ),
                    child: Row(
                      crossAxisAlignment: CrossAxisAlignment.center,
                      children: [
                        Text(
                          'Todo',
                          style:  TextStyle(
                            fontSize: 16,
                            fontFamily: 'OpenSans',
                            color: curSubImageIndex == 999 ? Colors.red : Colors.black
                          ),
                        ),
                        
                      ],
                    ),
                  ),
                ),
                for(var index = 0; index < categoryList.length; index++)
                  GestureDetector(
                    onTap: () {
                      setState(() {
                        curSubImageIndex = categoryList[index]['id'];
                        dataList = filterItemsByCategory(allDataList, curSubImageIndex);
                      });
                      
                    },
                    child: Container(
                      margin: const EdgeInsets.only(top: 12, left: 12),
                      padding: const EdgeInsets.only(left: 16, right: 16, top: 4, bottom: 4),
                      decoration: BoxDecoration(
                        border: Border.all(width: 0.5, color: const Color.fromARGB(255, 211, 211, 211)),
                        color: const Color.fromRGBO(255, 255, 255, .85),
                        borderRadius: const BorderRadius.all(Radius.circular(20)),
                      ),
                      child: Row(
                        crossAxisAlignment: CrossAxisAlignment.center,
                        children: [
                          Text(
                            categoryList[index]['category'],
                            style:  TextStyle(
                              fontSize: 16,
                              fontFamily: 'OpenSans',
                              color: curSubImageIndex == categoryList[index]['id'] ? Colors.red : Colors.black
                            ),
                          ),
                          
                        ],
                      ),
                    ),
                  ),
                const SizedBox(width: 12,)
              ]
            ),
          ),
          isLoading ? 
          const Expanded(child: Column(
            mainAxisAlignment: MainAxisAlignment.center,
            children: [
              LoadingSpinner()
            ],
          ) )
          : Expanded(child: dataList.isEmpty ?  Column(
            mainAxisAlignment: MainAxisAlignment.center,
            children: [
              SizedBox(
                height: 128,
                child: Image.asset('images/empty.png'),
              ),  
            ],
          
        ) :
        Padding(
          padding:
              const EdgeInsets.only(top: 10, left: 10, right: 10, bottom: 10),
          child: SingleChildScrollView(
            controller: controller,
            child: Align(
              alignment: Alignment.topLeft,
              child: Wrap(
                spacing: 10.0,
                runSpacing: 10.0,
                children: [
                  // for (var recommendImgItem in favoritePhotoList)
                  for (int index = 0; index < dataList.length; index++)
                    GestureDetector(
                      onTap: () {
                        Navigator.push(
                          context,
                          MaterialPageRoute(
                            builder: (context) => DetailPage(
                              imgId: dataList[index]['id'], gif: dataList[index]['gif']
                            ),
                          ),
                        );
                      },
                      child: Stack(
                        children: [
                          SizedBox(
                            width: (sizewidth - 30) / 2,
                            height: (sizewidth - 30) / 2,
                            // decoration: BoxDecoration(
                            //   image: DecorationImage(
                            //       image:
                            //           AssetImage(recommendImgItem['imgurl']),
                            //       fit: BoxFit.fitWidth),
                            //   borderRadius: BorderRadius.circular(8),
                            //   color: const Color.fromARGB(8, 0, 0, 0),
                            // ),
                            child: ClipRRect(
                              borderRadius: BorderRadius.circular(4),
                              child:CachedNetworkImage(
                                imageUrl: "https://apken.oss-us-west-1.aliyuncs.com/goodmorning-es/images/${dataList[index]['id']}.${dataList[index]['gif'] == 1 ? 'gif' : 'webp?x-oss-process=image/resize,p_40'}",
                                placeholder: (context, url) => const LoadingSpinner(), // 占位图
                                errorWidget: (context, url, error) => const Icon(Icons.error), // 错误图标
                                fit: BoxFit.cover,
                              )
                            ),
                          ),
                          Positioned(
                            bottom: 0,
                            left: 0,
                            right: 0,
                            child: Container(
                              padding: const EdgeInsets.only(
                                  left: 10, right: 10, bottom: 10),
                              decoration: const BoxDecoration(
                                borderRadius: BorderRadius.only(
                                  bottomLeft: Radius.circular(8),
                                  bottomRight: Radius.circular(8),
                                ),
                                gradient: LinearGradient(
                                  begin: Alignment.topLeft,
                                  end: Alignment.bottomLeft,
                                  colors: [
                                    Color.fromRGBO(0, 0, 0, 0),
                                    Color.fromRGBO(0, 0, 0, 0.5)
                                  ],
                                ),
                              ),
                              height: 80,
                              child: Row(
                                mainAxisAlignment:
                                    MainAxisAlignment.spaceBetween,
                                crossAxisAlignment: CrossAxisAlignment.end,
                                children: [
                                  GestureDetector(
                                    onTap: () async {
                                      List<String> favoriteList = await _getIntList();
                                      // print(dataList[index]['id']);
                                      favoriteList.remove(dataList[index]['id'].toString());
                                      dataList.removeWhere((item) => item['id'] == dataList[index]['id']);
                                      setState(() {
                                        favoriteList = favoriteList;
                                        dataList = dataList;
                                      });
                                      // print('000');
                                      // print(favoriteList);
                                      _saveIntList(favoriteList);
                                    },
                                    child: const Icon(
                                      Icons.favorite,
                                      size: 28,
                                      color:  Color.fromARGB(255, 252, 229, 13)
                                    ),
                                  ),
                                  // GestureDetector(
                                  //   onTap: () async {
                                  //     await shareAssetImage(
                                  //         recommendImgItem['imgurl']);
                                  //   },
                                  //   child: const Icon(
                                  //     Icons.share,
                                  //     size: 28,
                                  //     color: Colors.white,
                                  //   ),
                                  // ),
                                ],
                              ),
                            ),
                          ),
                          if(dataList[index]['gif'] == 1)
                          Positioned(
                            left: 5,
                            top: 5,
                            child: Container(
                              width: 36,
                              height: 28,
                              decoration: BoxDecoration(
                                borderRadius: BorderRadius.circular(18),
                                color: const Color.fromRGBO(255, 255, 255, .7),
                              ),
                              child: const Center(
                                child: Text('GIF',style: TextStyle( fontSize: 14),),
                              ),
                            )
                          ),
                        ],
                      ),
                    ),
                ],
              ),
            ),
          ),
        ))
        ]

          
      ]
    ));
    // return isLoading ? 
    //   const Column(
    //     mainAxisAlignment: MainAxisAlignment.center,
    //     children: [
    //       LoadingSpinner()
    //     ],
    //   ) 
    //   : dataList.isEmpty ? Align(
    //         child: Column(
    //           mainAxisAlignment: MainAxisAlignment.start,
    //           children: [
    //             const SizedBox(
    //               height: 50,
    //             ),
    //             SvgPicture.asset(
    //               'images/category/nodata.svg',
    //               height: 200,
    //               width: 200,
    //             ),
    //             const SizedBox(height: 16),
    //             const Text(
    //               'No Favorite Quotes Found!\nPlease Add Some Quotes',
    //               style: TextStyle(
    //                 color: Colors.black87,
    //                 fontSize: 16,
    //                 fontFamily: 'OpenSans',
    //               ),
    //               textAlign: TextAlign.center,
    //             )
    //           ],
    //         ),
    //       ) :
    //     Padding(
    //         padding:
    //             const EdgeInsets.only(top: 10, left: 10, right: 10, bottom: 10),
    //         child: SingleChildScrollView(
    //           controller: controller,
    //           child: Align(
    //             alignment: Alignment.topLeft,
    //             child: Wrap(
    //               spacing: 10.0,
    //               runSpacing: 10.0,
    //               children: [
    //                 // for (var recommendImgItem in favoritePhotoList)
    //                 for (int index = 0; index < dataList.length; index++)
    //                   GestureDetector(
    //                     onTap: () {
    //                       Navigator.push(
    //                         context,
    //                         MaterialPageRoute(
    //                           builder: (context) => DetailPage(
    //                             imgId: dataList[index]['id'], gif: dataList[index]['gif']
    //                           ),
    //                         ),
    //                       );
    //                     },
    //                     child: Stack(
    //                       children: [
    //                         Container(
    //                           width: (sizewidth - 30) / 2,
    //                           height: (sizewidth - 30) / 2,
    //                           // decoration: BoxDecoration(
    //                           //   image: DecorationImage(
    //                           //       image:
    //                           //           AssetImage(recommendImgItem['imgurl']),
    //                           //       fit: BoxFit.fitWidth),
    //                           //   borderRadius: BorderRadius.circular(8),
    //                           //   color: const Color.fromARGB(8, 0, 0, 0),
    //                           // ),
    //                           child: ClipRRect(
    //                             borderRadius: BorderRadius.circular(8),
    //                             child:CachedNetworkImage(
    //                               imageUrl: "https://apken.oss-us-west-1.aliyuncs.com/goodmorning-es/images/${dataList[index]['id']}.${dataList[index]['gif'] == 1 ? 'gif' : 'webp'}",
    //                               placeholder: (context, url) => const LoadingSpinner(), // 占位图
    //                               errorWidget: (context, url, error) => const Icon(Icons.error), // 错误图标
    //                               fit: BoxFit.cover,
    //                             )
    //                           ),
    //                         ),
    //                         Positioned(
    //                           bottom: 0,
    //                           left: 0,
    //                           right: 0,
    //                           child: Container(
    //                             padding: const EdgeInsets.only(
    //                                 left: 10, right: 10, bottom: 10),
    //                             decoration: const BoxDecoration(
    //                               borderRadius: BorderRadius.only(
    //                                 bottomLeft: Radius.circular(8),
    //                                 bottomRight: Radius.circular(8),
    //                               ),
    //                               gradient: LinearGradient(
    //                                 begin: Alignment.topLeft,
    //                                 end: Alignment.bottomLeft,
    //                                 colors: [
    //                                   Color.fromRGBO(0, 0, 0, 0),
    //                                   Color.fromRGBO(0, 0, 0, 0.5)
    //                                 ],
    //                               ),
    //                             ),
    //                             height: 80,
    //                             child: Row(
    //                               mainAxisAlignment:
    //                                   MainAxisAlignment.spaceBetween,
    //                               crossAxisAlignment: CrossAxisAlignment.end,
    //                               children: [
    //                                 GestureDetector(
    //                                   onTap: () async {
    //                                     List<String> favoriteList = await _getIntList();
    //                                     print(dataList[index]['id']);
    //                                     favoriteList.remove(dataList[index]['id'].toString());
    //                                     dataList.removeWhere((item) => item['id'] == dataList[index]['id']);
    //                                     setState(() {
    //                                       favoriteList = favoriteList;
    //                                       dataList = dataList;
    //                                     });
    //                                     print('000');
    //                                     print(favoriteList);
    //                                     _saveIntList(favoriteList);
    //                                   },
    //                                   child: const Icon(
    //                                     Icons.favorite,
    //                                     size: 28,
    //                                     color:  Color.fromARGB(255, 252, 229, 13)
    //                                   ),
    //                                 ),
    //                                 // GestureDetector(
    //                                 //   onTap: () async {
    //                                 //     await shareAssetImage(
    //                                 //         recommendImgItem['imgurl']);
    //                                 //   },
    //                                 //   child: const Icon(
    //                                 //     Icons.share,
    //                                 //     size: 28,
    //                                 //     color: Colors.white,
    //                                 //   ),
    //                                 // ),
    //                               ],
    //                             ),
    //                           ),
    //                         ),
    //                         if(dataList[index]['gif'] == 1)
    //                         Positioned(
    //                           left: 5,
    //                           top: 5,
    //                           child: Container(
    //                             width: 36,
    //                             height: 28,
    //                             decoration: BoxDecoration(
    //                               borderRadius: BorderRadius.circular(18),
    //                               color: const Color.fromRGBO(255, 255, 255, .7),
    //                             ),
    //                             child: const Center(
    //                               child: Text('GIF',style: TextStyle( fontSize: 14),),
    //                             ),
    //                           )
    //                         ),
    //                       ],
    //                     ),
    //                   ),
    //               ],
    //             ),
    //           ),
    //         ),
    //       );
  }
}
